package test;

import com.opensymphony.xwork2.ActionContext;
import com.opensymphony.xwork2.ActionSupport;

public class LoginAction extends ActionSupport {

	private static final long serialVersionUID = 1L;
	private String username;
	private String password;
	private String tip;

	public String getUsername() {
		return username;
	}

	public String getPassword() {
		return password;
	}

	public void setUsername(String username) {
		this.username = username;
	}

	public void setPassword(String password) {
		this.password = password;
	}

	public String getTip() {
		return tip;
	}

	public void setTip(String tip) {
		this.tip = tip;
	}

	// Action包含的注册控制逻辑
	public String regist() throws Exception {
		ActionContext.getContext().getSession().put("user", getUsername());
		setTip("恭喜您" + getUsername() + "注册成功！");
		return SUCCESS;
	}

	public String execute() throws Exception {
		if (getUsername().equals("leifchen") && getPassword().equals("123")) {
			ActionContext.getContext().getSession().put("user", getUsername());
			return SUCCESS;
		} else {
			return ERROR;
		}
	}
}
